package temperature;

import org.junit.*;
import static org.junit.Assert.*;
import java.math.BigDecimal;

/**
 * @author Tom Jacobs & Ewoud De Moor
 * @version 3.0
 */
public class TemperatureTest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test (expected = IllegalArgumentException.class)
	public void newTemperatureException_invalidTemperatureScale(){
		TemperatureScale temperatureScale = null;
		@SuppressWarnings("unused")
		Temperature newTemperature = new Temperature(BigDecimal.ZERO, temperatureScale);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void newTemperatureException_invalidNumeral_null(){
		@SuppressWarnings("unused")
		Temperature newTemperature = new Temperature(null);
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void newTemperatureException_invalidNumeral_toLow(){
		@SuppressWarnings("unused")
		Temperature newTemperature = new Temperature(BigDecimal.valueOf(-273.16));
	}
	
	@Test
	public void getAbsoluteZero_Values() {
		BigDecimal absoluteZeroCelsius = BigDecimal.valueOf(-273.15);
		assertEquals(absoluteZeroCelsius,Temperature.getAbsoluteZero(TemperatureScale.CELSIUS));
		BigDecimal absoluteZeroKelvin = BigDecimal.ZERO;
		assertEquals(absoluteZeroKelvin,Temperature.getAbsoluteZero(TemperatureScale.KELVIN));
		BigDecimal absoluteZeroFahrenheit = BigDecimal.valueOf(-459.67);
		assertEquals(absoluteZeroFahrenheit,Temperature.getAbsoluteZero(TemperatureScale.FAHRENHEIT));
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void getAbsoluteZeroException_invalidTemperatureScale(){
		Temperature.getAbsoluteZero(null);
	}
	
	@Test
	public void toCelsius_Values() {
		Temperature temperatureCelsiusReference = new Temperature(BigDecimal.valueOf(16), TemperatureScale.CELSIUS);
		
		Temperature temperatureCelsius = new Temperature(BigDecimal.valueOf(16), TemperatureScale.CELSIUS);
		assertEquals(0,temperatureCelsius.toCelsius().compareTo(temperatureCelsiusReference));
		Temperature temperatureKelvin = new Temperature(BigDecimal.valueOf(289.15), TemperatureScale.KELVIN);
		assertEquals(0,temperatureKelvin.toCelsius().compareTo(temperatureCelsiusReference));
		Temperature temperatureFahrenheit = new Temperature(BigDecimal.valueOf(60.8), TemperatureScale.FAHRENHEIT);
		assertEquals(0,temperatureFahrenheit.toCelsius().compareTo(temperatureCelsiusReference));
	}
	
	@Test
	public void toScale_Values(){
		Temperature temperatureCelsiusReference = new Temperature(BigDecimal.valueOf(16), TemperatureScale.CELSIUS);
		
		Temperature temperatureKelvin = temperatureCelsiusReference.toScale(TemperatureScale.KELVIN);
		assertEquals(0,temperatureKelvin.toCelsius().compareTo(temperatureCelsiusReference));
		
		Temperature temperatureFahrenheit = temperatureCelsiusReference.toScale(TemperatureScale.FAHRENHEIT);
		assertEquals(0,temperatureFahrenheit.toCelsius().compareTo(temperatureCelsiusReference));
		
	}
	
	@Test
	public void toScale_Values_Other(){
		Temperature temperatureCelsiusReference = new Temperature(BigDecimal.valueOf(5.55555555), TemperatureScale.CELSIUS);
		Temperature testTemperature = temperatureCelsiusReference.toScale(TemperatureScale.FAHRENHEIT).toScale(TemperatureScale.KELVIN)
			.toScale(TemperatureScale.CELSIUS).toScale(TemperatureScale.KELVIN).toScale(TemperatureScale.FAHRENHEIT)
			.toCelsius().toScale(TemperatureScale.FAHRENHEIT).toScale(TemperatureScale.FAHRENHEIT);
		assertEquals(0,testTemperature.toCelsius().compareTo(temperatureCelsiusReference));
	}
	
	@Test
	public void temperatureToString_Celsius(){
		Temperature testTemperature = new Temperature(BigDecimal.valueOf(100),TemperatureScale.CELSIUS);
		assertEquals("100 \u00B0C", testTemperature.toString());
	}
	
	@Test
	public void temperatureToString_Fahrenheit(){
		Temperature testTemperature = new Temperature(BigDecimal.valueOf(100),TemperatureScale.FAHRENHEIT);
		assertEquals("100 \u00B0F", testTemperature.toString());
	}
	
	@Test
	public void temperatureToString_Kelvin(){
		Temperature testTemperature = new Temperature(BigDecimal.valueOf(100),TemperatureScale.KELVIN);
		assertEquals("100 K", testTemperature.toString());
	}
	
	@Test
	public void testEqualTemperatures(){
		Temperature temp1 = new Temperature(BigDecimal.valueOf(100));
		Temperature temp2 = new Temperature(BigDecimal.valueOf(100));
		temp2 = temp2.toScale(TemperatureScale.FAHRENHEIT);
		temp2 = temp2.toCelsius();
		assertEquals(temp1, temp2);
		assertEquals(temp1.hashCode(), temp2.hashCode());
	}
	
}
